package com.yun.algorithmproblem.leetcode;

public class Leetcode3375 {

	public static void main(String[] args) {
		Leetcode3375 obj = new Leetcode3375();
		System.out.println(obj.minOperations(new int[]{5,2,5,4,5}, 2));
	}
	public int minOperations(int[] nums, int k) {
		int[] cnt = new int[100];
		int ans=0;
		int cntK=0;
		for (int num : nums) {
			if(num<k){
				return -1;
			}
			if(num==k){
				cntK++;
			}
			cnt[num - 1]++;
			if (cnt[num - 1] == 1) {
				ans++;
			}
		}
		return cntK>0?ans-1:ans;
	}
}
